package com.xbongbong.paas.service.aliyun;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.PlatFormEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Getter
public enum  CloudCodeChartEnum {
    ALIYUN_CALLCENTER("cloudCode_","AliyunCenter","","","constant.chartI18Constant.aliyun_callcenter","","icon-yunhu",true,""),
    // 首页
    ALIYUN_CALLCENTER_HOME("cloudCode_","AliyunCenter","multi-page/home/home-page.html#/","multi-page/dingtalk.html#/index","constant.chartI18Constant.aliyun_callcenter_home","#FF8E3D","icon-zhuye",false,PlatFormEnum.ALL.getValue(), 3),
    // 通话记录
    ALIYUN_CALLCENTER_CALL_RECORDS("cloudCode_","AliyunCenter","multi-page/home/call-records.html#/","multi-page/dingtalk.html#/call-log","constant.chartI18Constant.aliyun_callcenter_call_records","#1BC4A4","icon-yun1-01",false,PlatFormEnum.ALL.getValue(), 1, 2, 3),
    // 拨号盘
    ALIYUN_CALLCENTER_XBB_CLOUD_CALL("cloudCode_","AliyunCenter","","multi-page/dingtalk.html#/call-out","constant.chartI18Constant.aliyun_callcenter_xbb_clooud_call","#5190ED","icon-tonghuajilu",false, PlatFormEnum.DINGTALK.getValue(),1, 2, 3),

    // --------------- 管理中心的菜单 ---------------
    MANAGEMENT_CENTER("cloudCode_","managementCenter","","","constant.chartI18Constant.cloud_call_center","","icon-yunhu",true, ""),
    // 号码管理
    NUMBER_MANAGEMENT("cloudCode_","managementCenter","multi-page/manage-center/number-manage.html#/","multi-page/manage-center/number-manage.html#/","constant.chartI18Constant.number_management","#5190ED","icon-purchaseManage",false, PlatFormEnum.ALL.getValue(), 3, 4),
    // 坐席
    SEATS_MANAGEMENT("cloudCode_","managementCenter","multi-page/manage-center/seats-manage.html#/","multi-page/manage-center/seats-manage.html#/","constant.chartI18Constant.seats_management","#5190ED","icon-productmanage",false, PlatFormEnum.ALL.getValue(), 3, 4),
    // 技能组
    SKILL_GROUPS_MANAGEMENT("cloudCode_","managementCenter","multi-page/manage-center/skills-group-manage.html#/","multi-page/manage-center/skills-group-manage.html#/","constant.chartI18Constant.skill_groups_management","#5190ED","icon-menu-stock",false, PlatFormEnum.ALL.getValue(),  3, 4),
    // 设置
    SETTINGS_MANAGEMENT("cloudCode_","managementCenter","multi-page/manage-center/settings.html#/","multi-page/manage-center/settings.html#/","constant.chartI18Constant.settings_management","#5190ED","icon-productionOrder",false, PlatFormEnum.ALL.getValue(), 3, 4),
    // 号码申请
    NUMBER_APPLY("cloudCode_","managementCenter","multi-page/manage-center/number-apply.html#/","multi-page/manage-center/number-apply.html#/","constant.chartI18Constant.number_apply","#5190ED","icon-productStock",false, PlatFormEnum.ALL.getValue(), 3, 4),

    ;




    CloudCodeChartEnum(String alias,String type,String url,String mobileUrl, String name,String color,String icon,boolean isParent,String platform, Integer... roles) {
        this.alias = alias;
        this.type = type;
        this.url = url;
        this.mobileUrl = mobileUrl;
        this.name = name;
        this.color = color;
        this.icon = icon;
        this.isParent = isParent;
        this.platform = platform;
        this.roles = roles;
    }
    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    private String alias;
    private String type;
    private String url;
    private String mobileUrl;
    private String name;
    private String color;
    private String icon;
    private boolean isParent;
    private String platform;
    /**
     * 权限集合 1坐席Agent，2技能组组长Manager，3管理员Admin
     */
    private Integer[] roles;

    public static  CloudCodeChartEnum getParentByType(String type, String platform, Integer facilitators){
        List<CloudCodeChartEnum> values = getParentEnumList(platform, facilitators);
        for(CloudCodeChartEnum temp:values){
            if( temp.getType().equals(type)&&temp.isParent()){
                return temp;
            }
        }
        return null;
    }

    public static List<CloudCodeChartEnum> getChildListByType(String type, String platform, Integer facilitators){
        List<CloudCodeChartEnum> list = new ArrayList<>();
        List<CloudCodeChartEnum> values = getchartEnumList(platform, facilitators);
        for(CloudCodeChartEnum temp:values){
            if( temp.getType().equals(type)&&!temp.isParent()){
                list.add(temp);
            }
        }
        return list;
    }

    private static List<CloudCodeChartEnum> getParentEnumList(String platform, Integer facilitators){
        if (Objects.equals(0, facilitators)) {
            return Arrays.asList(values());
        }
        if (Objects.equals(1, facilitators)) {
            if (Objects.equals(PlatFormEnum.DINGTALK.getValue(), platform)) {
                return Arrays.asList(ALIYUN_CALLCENTER);
            }
            return Arrays.asList(ALIYUN_CALLCENTER, MANAGEMENT_CENTER);
        }
        if (Objects.equals(2, facilitators)) {
            return Arrays.asList(ALIYUN_CALLCENTER, MANAGEMENT_CENTER);
        }
        return new ArrayList<>();
    }

    private static List<CloudCodeChartEnum> getchartEnumList(String platform, Integer facilitators){
        if (Objects.equals(0, facilitators)) {
            return Arrays.asList(values());
        }
        if (Objects.equals(1, facilitators)) {
            if (Objects.equals(PlatFormEnum.DINGTALK.getValue(), platform)) {
                return Arrays.asList(ALIYUN_CALLCENTER_CALL_RECORDS);
            }
            return Arrays.asList(ALIYUN_CALLCENTER_CALL_RECORDS, SEATS_MANAGEMENT, SETTINGS_MANAGEMENT);
        }
        if (Objects.equals(2, facilitators)) {
            return Arrays.asList(ALIYUN_CALLCENTER_CALL_RECORDS, SEATS_MANAGEMENT, SETTINGS_MANAGEMENT);
        }
        return new ArrayList<>();
    }







}
